package  
{
	import org.flixel.*;

	public class PathFinder extends FlxState
	{
		[Embed(source = '../assets/mapCSV_Group1_Map1.csv', mimeType = 'application/octet-stream')] private var mapCSV:Class;
		[Embed(source = '../assets/tiles.png')] private var tilesPNG:Class;
		
		private var map:FlxTilemap;
		private var path:FlxPath;
		private var dude:FlxSprite;
		
		public function PathFinder() 
		{
		}
		
		override public function create():void
		{
			FlxG.bgColor = 0xff0080FF;
			
			dude = new FlxSprite(1 * 16, 38 * 16);
			//dude.width = 14;
			//dude.height = 14;
			
			map = new FlxTilemap();
			map.loadMap(new mapCSV, tilesPNG, 16, 16, 0, 0, 1, 56);
			map.solid = true;
			
			path = map.findPath(dude.getMidpoint(), new FlxPoint((38 * 16) + 8, (1 * 16) + 8));
			
			if (path != null)
			{
				//	He starts out ok, then he gets stuck :)
				dude.followPath(path, 120, FlxObject.PATH_YOYO);
			}
			
			//FlxG.camera.bounds = new FlxRect(0, 0, map.width, map.height);
			
			FlxG.worldBounds = new FlxRect(0, 0, map.width, map.height);
			FlxG.camera.follow(dude, FlxCamera.STYLE_TOPDOWN);
			
			add(dude);
			add(map);
		}
		
		override public function update():void
		{
			super.update();
			
			//path.drawDebug();
			
			/*
			if (FlxG.keys.LEFT)
			{
				dude.x -= 2;
			}
			else if (FlxG.keys.RIGHT)
			{
				dude.x += 2;
			}
			
			if (FlxG.keys.UP)
			{
				dude.y -= 2;
			}
			else if (FlxG.keys.DOWN)
			{
				dude.y += 2;
			}
			*/
			
			//FlxG.collide(dude, map);
		}
		
	}

}